<?php
/**
 * 盈亏报表
 *
 *
 *
 * @copyright  Copyright (c) 2014-2015 TuntronKJ Inc. (http://www.tuntron.com)
 * @license    http://www.tuntron.com
 * @link       http://www.tuntron.com
 * @since      File available since Release v1.1
 */
defined('InTuntronKJ') or exit('Access Invalid!');
class userprofitlossControl extends BaseLotteryHallControl{
	public function indexOp(){
		
		$user_model = Model('member');

		$uid = $_SESSION['uid'];
		$memberinfo = $user_model->getMemberInfo(array('uid'=>$uid));

		$fromTime = strtotime($_GET['start']);
		$toTime = strtotime($_GET['end']);
		
		if($fromTime && $toTime){
			$fromTime = $fromTime+3600*3;
			$toTime = $toTime+3600*3;
		}else{
			$today_zero = strtotime('today');
			$time = time();
			$fromTime = $today_zero+3600*3;			//查询起始时间
			if($fromTime > $time){
				$toTime = $fromTime;				//查询结束时间
				$fromTime = $today_zero-3600*21;
			}else{
				$toTime = $fromTime+3600*24;
			}
		}	
		$param['beginDate'] = date('Y-m-d',$fromTime);
		$param['endDate'] = date("Y-m-d",$toTime);
		
		$betTimeWhere="and actionTime between $fromTime and $toTime";
		$cashTimeWhere="and c.actionTime between $fromTime and $toTime";
		$rechargeTimeWhere="and r.actionTime between $fromTime and $toTime";
		$fanDiaTimeWhere="and actionTime between $fromTime and $toTime";
		$fanDiaTimeWhere2="and l.actionTime between $fromTime and $toTime";
		$brokerageTimeWhere=$fanDiaTimeWhere2;	

		$data['uid'] = $uid;
		$file = "username,coin,uid,parentId,(select sum(b.mode * b.beiShu * b.actionNum) from ssc_bets b where b.`uid`= $uid and isDelete=0 $betTimeWhere) betAmount, (select sum(b.bonus) from ssc_bets b where b.`uid`= $uid $betTimeWhere) zjAmount,(select sum(c.amount) from ssc_member_cash c where c.`uid`= $uid and c.state=0 $cashTimeWhere) cashAmount,(select sum(r.amount) from ssc_member_recharge r where r.`uid`= $uid and r.state in(1,2,9) $rechargeTimeWhere) rechargeAmount,(select sum(l.coin) from ssc_coin_log l where l.`uid`= $uid and l.liqType in(2,3) $fanDiaTimeWhere) fanDianAmount";
		$member_list = $user_model->getMemberReportInfo($data,$file);

		Tpl::output('memberinfo',$memberinfo);
		Tpl::output('member_list',$member_list);
		Tpl::output('param',$param);
		Tpl::showpage('userprofitloss');
	}



}
